package com.right.health.app.net;

import android.text.TextUtils;

import com.magics.http.model.HttpParams;
import com.right.health.app.app.App;
import com.right.health.app.bean.DoctorDetailResponse;
import com.right.health.app.bean.DoctorResponse;
import com.right.health.app.bean.DoctorScheduleResponse;
import com.right.health.app.bean.FindDoctorResponse;
import com.right.health.app.constants.AppConfig;

import org.json.JSONException;
import org.json.JSONObject;

/*
 * Created by hopeliao on 2019-12-20
 *
 */
public class DoctorApi extends IBaseApi {

     public void getDoctor(String syscommunityCode, String deptid, String startTime, String endTime, int pageNo) {
         HttpParams params = new HttpParams();
         try {
             JSONObject jsonObject = new JSONObject();
             jsonObject.put("deptid", deptid);
             jsonObject.put("startTime", startTime);
             jsonObject.put("endTime", endTime);

             if(!TextUtils.isEmpty(syscommunityCode)) {
                 jsonObject.put("syscommunitycode", syscommunityCode);
             }


             PageUtil.addPageJson(jsonObject, pageNo, AppConfig.PAGE_SIZE);
             params.addFormParam("jsonstr", jsonObject.toString());
         } catch (JSONException e) {
             e.printStackTrace();
         }
         doPostJson(HttpConstants.API_GET_DOCTOR, params, DoctorResponse.class);
     }

     public void getDoctorSchedule(String syscommunityCode,String doctorid, String doctorlevelcode, String startTime ,String endTime) {
         HttpParams params = new HttpParams();
         try {
             JSONObject jsonObject = new JSONObject();
             jsonObject.put("doctorid", doctorid);
             jsonObject.put("doctorlevelcode", doctorlevelcode);
             jsonObject.put("startTime", startTime);
             jsonObject.put("endTime", endTime);
             if(!TextUtils.isEmpty(syscommunityCode)) {
                 jsonObject.put("syscommunitycode", syscommunityCode);
             }
             params.addFormParam("jsonstr", jsonObject.toString());
         } catch (JSONException e) {
             e.printStackTrace();
         }
         doPostJson(HttpConstants.API_DOCTOR_SCHEDULE, params, DoctorScheduleResponse.class);
     }

    public void findDoctorList(int pageNo,String keyword) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            if (!TextUtils.isEmpty(keyword)) {
                jsonObject.put("searchkey", keyword);
            }
            PageUtil.addPageJson(jsonObject, pageNo, AppConfig.PAGE_SIZE);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FIND_DOCTOR_LIST, params, FindDoctorResponse.class);
    }

    public void focusDoctorList(String keyword) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            if (!TextUtils.isEmpty(keyword)) {
                jsonObject.put("searchkey", keyword);
            }
            jsonObject.put("isfocus", 1);
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FIND_DOCTOR_LIST, params, FindDoctorResponse.class);
    }

    public void getDoctorDetail(String doctorId) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("doctorid", doctorId);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_DOCTOR_DETAIL, params, DoctorDetailResponse.class);
    }

    public void followDoctor(String doctorId) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("doctorid", doctorId);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FOLLOW_DOCTOR, params, null);
    }

    public void cancelFollowDoctor(String doctorId) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("doctorid", doctorId);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_CANCLE_FOLLOW_DOCTOR, params, null);
    }
}
